package com.car.shopping.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.commons.core.model.Result;
import com.car.shopping.client.CarAccountClient;
import com.car.shopping.client.model.user.SelectById;
import com.car.shopping.controller.form.PageForm;
import com.car.shopping.entity.GoodsInfo;
import com.car.shopping.entity.GoodsModifyLog;
import com.car.shopping.mapper.GoodsModifyLogMapper;
import com.car.shopping.service.GoodsModifyLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 董旭
 * @since 2024-08-28
 */
@Service
public class GoodsModifyLogServiceImpl extends ServiceImpl<GoodsModifyLogMapper, GoodsModifyLog> implements GoodsModifyLogService {

    @Autowired
    private GoodsModifyLogMapper goodsModifyLogMapper;

    @Autowired
    private CarAccountClient carAccountClient;

    @Override
    public Page<GoodsModifyLog> findLogForPage(PageForm form) throws Exception {
        // 创建分页对象
        Page<GoodsModifyLog> page = new Page<>(form.getPageNum(), form.getPageSize());

        // 创建查询条件
        QueryWrapper<GoodsModifyLog> queryWrapper = new QueryWrapper<>();
        // 你可以在这里添加额外的查询条件，例如：
        // queryWrapper.eq("admin_id", someAdminId);

        // 执行分页查询
        Page<GoodsModifyLog> resultPage = goodsModifyLogMapper.selectPage(page, queryWrapper);




        return resultPage;
    }

    @Override
    public SelectById selectById(Integer adminId) throws Exception {
        // 调用远程服务获取管理员信息
        Result<SelectById> result = carAccountClient.selectById(adminId);

        // 检查结果是否成功，并返回数据
        if (result.getCode() == 200 && result.getData() != null) {
            return result.getData();
        } else {
            // 如果没有找到数据或返回码不为200，处理异常
            throw new Exception("管理员信息未找到或请求失败");
        }
    }



}
